package com.yishe.biz.wx;

import com.yishe.biz.BaseBiz;
import com.yishe.biz.mysql.WxUserBiz;
import com.yishe.entites.mysql.WxUser;
import com.yishe.entites.mysql.WxUserMemberInfo;
import com.yishe.mapper.mysql.WxUserMapper;
import com.yishe.mapper.mysql.WxUserMemberInfoMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * @author : chusifeng
 * @version :
 * @date :Create in 2021/4/14 14:14
 * @description: 用户系统处理类
 * @package com.yishe.biz.wx
 * @className WxBiz
 */
@Service
@Slf4j
public class WxUserInfoBiz extends BaseBiz<WxUserMapper,WxUser> {
    @Resource
    private WxUserMemberInfoMapper wxUserMemberInfoMapper;
    @Resource
    private WxUserBiz wxUserBiz;

    /**
     * 根据openid获取用户的会员信息
     *
     * @param params
     * @return
     */
    public Map<String, Object> getUserMemberByOpenid(Map<String, String> params) {
        return wxUserMemberInfoMapper.getUserMemberByOpenid(params);
    }

    /**
     * 根据account获取用户信息数据
     *
     * @param params
     * @return
     */
    public Map<String,Object> getUserInfo(Map<String, String> params) {
        Map<String,Object> reslt = new HashMap<>(2);
        String account = params.get("account");
        WxUser wxUser = new WxUser();
        wxUser.setWxAccount(account);
        wxUser =  wxUserBiz.selectOne(wxUser);
        reslt.put("wxUser",wxUser);
        WxUserMemberInfo wxUserMemberInfo = new WxUserMemberInfo();
        wxUserMemberInfo.setWxAccount(account);
        wxUserMemberInfo = wxUserMemberInfoMapper.selectOne(wxUserMemberInfo);
        reslt.put("wxUserMember",wxUserMemberInfo);
        return reslt;
    }

    public void saveUserInfo(WxUser wxUser) {
        if (null == wxUser.getId()){
            this.insert(wxUser);
        } else {
            this.updateById(wxUser);
        }
    }
}
